// pages/orderDetail/orderDetail.js
import Notify from '../../components/dist/notify/notify';
import Toast from '../../components/dist/toast/toast';
var core = require("../../utils/core.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading: false,
    id: '',
    orderInfo: '', //订单信息
    cap_info: '', //社区信息
    group_info: '',
    pay_type: '', //订单状态类型
    CountDown: '00:00', //倒计时显示字符串
    CountDownTime: '', //获取的倒计时的时间
    cutTimer: '', //倒计时定时器
    popshow: false, //提货码展示
    thmnum: '', //提货码二维码图片链接
    thmnum: [], //提货码数字数组
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    var id = options.id;
    this.setData({
      id: id
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () { },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getDetailList();
  },
  getDetailList: function () {
    var that = this;
    that.setData({
      loading: true
    })
    core.get("groupapp.order.get_detail", {
      id: that.data.id
    }, function (t) {
      console.log(t);
      if (t.error == 0) {
        that.setData({
          orderInfo: t.order_info,
          cap_info: t.cap_info,
          group_info: t.group_info
        })
        that.ProcessingData();
      } else {
        Toast('获取数据错误');
      }
      that.setData({
        loading: false
      })
    })
  },
  ProcessingData: function () { //处理数据
    var that = this;
    var order_status = that.data.orderInfo.pay_type;
    // console.log(order_status)
    that.setData({
      pay_type: 0
    })
    if (order_status == 0) { //状态是代付款
      that.setData({
        CountDownTime: that.data.orderInfo.count_down
      });
      that.cutTime();
    } else if (order_status == 3) {
      wx.setNavigationBarColor({
        frontColor: '#ffffff', // 必写项
        backgroundColor: '#fc4d4d', // 传递的颜色值
      })
    } else if (order_status == -1) {
      wx.setNavigationBarColor({
        frontColor: '#ffffff', // 必写项
        backgroundColor: '#312821', // 传递的颜色值
      })
    }



  },
  cutTime: function () { //倒计时方法
    var that = this;
    if (this.data.CountDownTime > 0) {
      console.log('小于2')
      that.data.cutTimer = setInterval(function () {
        if (that.data.CountDownTime < 1) {
          clearInterval(that.data.cutTimer);
          that.setData({
            CountDownTime: '00:00'
          })
        }
        var time = that.data.CountDownTime;
        that.setData({
          CountDownTime: time - 1
        })
        that.formatDuring(that.data.CountDownTime * 1000);
      }, 1000)
    } else { //倒计时完成
      console.log('小于1')
    }
  },
  formatDuring: function (mss) {
    var that = this;
    var days = parseInt(mss / (1000 * 60 * 60 * 24));
    var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
    var seconds = parseInt((mss % (1000 * 60)) / 1000);
    var timestr = '';
    if (minutes < 10) {
      minutes = '0' + minutes.toString()
    }
    if (seconds < 10) {
      seconds = '0' + seconds.toString()
    }
    timestr = minutes + ':' + seconds
    that.setData({
      CountDown: timestr
    })
  },
  contentTuanz: function (e) { //联系团长
    console.log(e);
    var phone = e.currentTarget.dataset.phone;
    wx.makePhoneCall({
      phoneNumber: phone // 仅为示例，并非真实的电话号码
    })
  },
  showthm: function (e) { //显示提货码
    console.log(e)
    var thmimg = e.currentTarget.dataset.thmimg;
    var thmnum = e.currentTarget.dataset.thmnum;
    var arr = thmnum.split('');
    console.log(arr);



    this.setData({
      popshow: true,
      thmnum: arr,
      thmimg: thmimg
    });

  },
  onPopshowClose: function () {
    this.setData({
      popshow: false
    });
  },
  toEvaluate: function (e) { //去评价
    console.log(e);
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    var that = this;
    clearInterval(that.data.cutTimer);
  },
  sqsh1: function (e) { //申请售后,整单
    console.log(e);
    var orderid = e.target.dataset.orderid;

    wx.navigateTo({
      url: '/pages/applicationAfterSale/applicationAfterSale?type=1&id=' + orderid,
    })



  },
  sqsh2: function (e) { //申请售后，单个商品
    console.log(e);
    var goodid = e.target.dataset.goodid;
    wx.navigateTo({
      url: '/pages/applicationAfterSale/applicationAfterSale?type=2&id=' + goodid,
    })




  },
  toxsjl:function(){
    wx.navigateTo({
      url: '/pages/ConsultationRecord/ConsultationRecord',
    })
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    var that = this;
    clearInterval(that.data.cutTimer);
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})